package com.mdx.tools.place;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PlaceConstants {
	
	public static final String PATH = "E:/码大侠科技资料/项目资料/村人口普查/数据库文档/地区sql/";
	
	public static final String FILE_SUFFIX = ".sql";
	
	public static final String SQL_MODEL = "insert into place (id, parent_id, code, name, level, is_leaf) values (";
	
	public static Map<String, String []> PROVINCE_SHORT_TO_CHILDREN_NAME = new HashMap<>();
	
	public static final List<Place> PLACE_LIST = new ArrayList<>();	
	
	public static final String PROVINC_PREFIX = "PC";
	
	public static final StringBuilder SB = new StringBuilder();
	
	public static String [] PROVINCE_ID = {};
	
	/**
	 * 生成省份id
	 * @param fileNameArr
	 * @param provincePrefix
	 * @return
	 */
	public static String [] GenerateParentId(String [] fileNameArr, String provincePrefix) {
		String parentIdStr = "";
		String prefix = PROVINC_PREFIX + "000";
		if(fileNameArr != null && fileNameArr.length > 0) {
			for(int i = 0; i < fileNameArr.length; i++) {
				//大于10，只有两个零
				if(i >= 10) {
					prefix = PROVINC_PREFIX + "00";
				}
				parentIdStr = parentIdStr+ prefix + i + ",";
			}
		}
		return parentIdStr.split(",");
	}
	
	/**
	 * 循环设置用户信息
	 */
	public static void setPlaceInfo() {
		for(int i = 0; i < PROVINCE_SHORT.length; i++) {
			String level = "2";
			if("PC".equals(PROVINCE_SHORT[i])) {
				level = "1";
			}
			Place place = new Place();
			place.setCodePrefix(PROVINCE_SHORT[i]);
			place.setFileName(SQL_FILE_NAME[i]);
			place.setIsLeaf(0);
			place.setLevel(level);
			place.setParentId(PROVINCE_ID[i]);
			place.setProvince(PROVINCE_SHORT_TO_CHILDREN_NAME.get(PROVINCE_SHORT[i]));
			PLACE_LIST.add(place);
		}
	}
	
	public static final String [] SQL_FILE_NAME = {
			"省", "北京", "天津", "河北省", "山西省", 
			"内蒙古自治区","辽宁省", "吉林省", "黑龙江省", "上海", 
			"江苏省", "浙江省", "安徽省", "福建省", "江西省", 
			"山东省", "河南省", "湖北省", "湖南省", "广东省", 
			"广西壮族自治区", "海南省", "重庆", "四川省", "贵州省", 
			"云南省", "西藏自治区", "陕西省", "甘肃省", "青海省", 
			"宁夏回族自治区", "新疆维吾尔自治区", "台湾省", "香港特别行政区", "澳门特别行政区"
	};
	
	public static final String [] PROVINCE_SHORT = {
		"PC", "BJ", "TJ", "HE", "SX", 
		"NM", "LN", "JL", "HL", "SH", 
		"JS", "ZJ", "AH", "FJ", "JX", 
		"SD", "HA", "HB", "HN", "GD", 
		"GX", "HI", "CQ", "SC", "GZ", 
		"YN", "XC", "SN", "GS", "QH",
		"LX", "XJ", "TW", "HK", "MO"
	};
	
	static{
		//省份设置城市信息
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("PC",PlaceInfoConstants.PC);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("BJ",PlaceInfoConstants.BJ);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("TJ",PlaceInfoConstants.TJ);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("HE",PlaceInfoConstants.HE);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("SX",PlaceInfoConstants.SX);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("NM",PlaceInfoConstants.NM);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("LN",PlaceInfoConstants.LN);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("JL",PlaceInfoConstants.JL);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("HL",PlaceInfoConstants.HL);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("SH",PlaceInfoConstants.SH);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("JS",PlaceInfoConstants.JS);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("ZJ",PlaceInfoConstants.ZJ);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("AH",PlaceInfoConstants.AH);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("FJ",PlaceInfoConstants.FJ);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("JX",PlaceInfoConstants.JX);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("SD",PlaceInfoConstants.SD);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("HA",PlaceInfoConstants.HA);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("HB",PlaceInfoConstants.HB);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("HN",PlaceInfoConstants.HN);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("GD",PlaceInfoConstants.GD);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("GX",PlaceInfoConstants.GX);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("HI",PlaceInfoConstants.HI);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("CQ",PlaceInfoConstants.CQ);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("SC",PlaceInfoConstants.SC);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("GZ",PlaceInfoConstants.GZ);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("YN",PlaceInfoConstants.YN);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("XC",PlaceInfoConstants.XC);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("SN",PlaceInfoConstants.SN);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("GS",PlaceInfoConstants.GS);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("QH",PlaceInfoConstants.QH);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("LX",PlaceInfoConstants.LX);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("XJ",PlaceInfoConstants.XJ);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("TW",PlaceInfoConstants.TW);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("HK",PlaceInfoConstants.HK);
		PROVINCE_SHORT_TO_CHILDREN_NAME.put("MO",PlaceInfoConstants.MO);
		//设置父id值
		PROVINCE_ID = GenerateParentId(SQL_FILE_NAME, PROVINC_PREFIX);
		setPlaceInfo();
	}
}
